package com.jlf.controller.engine.entity.index;

import com.jlf.core.engine.domain.SchemaIndexDO;
import jakarta.validation.constraints.*;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * 模型索引的输入参数
 *
 * @author wujr
 * 2023/7/16
 * @version 1.0
 * 【变更历史】
 * [wujr 2023/7/16 1.0 新增]
 */
@Getter
@Setter
public class SchemaIndexInput {
    @NotBlank(message = "索引名称不能为空")
    private String name;
    @NotEmpty(message = "索引字段不能为空")
    private List<String> columns;
    @NotNull(message = "索引类型不能为空")
    @Min(value = 1, message = "不支持的索引类型")
    @Max(value = 2, message = "不支持的索引类型")
    private Integer type;
    /**
     * 是否唯一
     */
    private Boolean uniqueness = false;
    private String remark;

    public SchemaIndexDO to(){
        SchemaIndexDO record = new SchemaIndexDO();
        record.setName(this.name);
        record.setType(this.type);
        record.setRemark(this.remark);
        record.setColumns(StringUtils.join(this.columns, ","));
        record.setUniqueness(this.uniqueness);

        return record;
    }
}
